<template>
  <div class="app-container">
    <el-form ref="form" style="width:25%" :model="account" label-width="80px">

      <el-form-item label="角色名称">
        <el-input v-model="account.gameName" disabled></el-input>
      </el-form-item>

      <el-form-item label="账号">
        <el-input v-model="account.account"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onsubmit()" style="margin-right:10px">提交</el-button>
        <a :href="'#/account/index'">
        <el-button>取消</el-button>
        </a>
      </el-form-item>
    </el-form>
  </div>
</template>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: auto;
  display: block;
}
</style>
<script>
import accountApi  from '@/api/account'
import axios from 'axios'
export default {

  data() {
    return {
      account: {
        id: this.$route.query.id,
        account:'',
        gameId:null
      }


    }
  },
  created() {
    let id = this.$route.query.id
     
    this.getAccountById(id)

  },
  methods: {
    //根据id获取道具信息
    getAccountById(id){
      accountApi.getAccountById(id).then(res => {
        console.log(res.data.account);
        this.account = res.data.account
      })
    },
    //点击提交
    onsubmit(){
      if(this.$route.query.id){
        //修改
        this.updateAccount()
      }
    },
    //更新道具
    updateAccount(){
      accountApi.updateAccount(this.account).then(res => {
          //弹窗提示
          this.$message({
            message: '修改成功',
            type: 'success'
          });
          //跳转
          this.$router.push("/account/index")
      })
    }
  }
}
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>